/*
 * @Author: your name
 * @Date: 2022-03-29 10:22:53
 * @LastEditTime: 2022-07-17 18:09:19
 * @LastEditors: YNT 2501512800@qq.com
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \22-03-19 智慧社区\pages\myrOder\index.js
 */

import SpecialModel from '../../api/venue'
import Dialog from '@vant/weapp/dialog/dialog'

Page({
  data: {
    nvabarData: {
      navigationBarTextStyle: 'black', // 胶囊主题 white || black
      navigationBarBackground: '#FEFEFE', // 导航栏背景色
      navigationBarTitleText: '我的订单',
    },
    allList: [],
    waitList: [],
    finishedList: [],
  },

  onLoad: function (options) {
    let _that = this
    SpecialModel.VenueList({})
      .then(({ data }) => {
        data.items.forEach((element) => {
          element.venv_time_end_time = element.venv_time_start_time.slice(0, 5)
          element.venv_time_end_time = element.venv_time_end_time.slice(0, 5)
        })
        let waitList = data.items.filter(function (item) {
          return item.status == '0'
        })
        let finishedList = data.items.filter(function (item) {
          return item.status == '1'
        })
        let outDataList = data.items.filter(function (item) {
          return item.status == '2'
        })

        _that.setData({
          waitList,
          finishedList,
          outDataList,
        })
      })
      .catch(({ errCode, data }) => {})
      .finally()
  },

  checkEr: function (e) {
    let id = e.target.dataset.id
    let waitList = this.data.waitList
    let target = waitList.filter((item) => {
      return item.id == id
    })
    console.log(target)
    this.setData({
      qrcodeUrl: target[0].qr_img,
      venv_name:target[0].venv_name,
    })
    Dialog({
      selector: '.prize_dialog',
      showConfirmButton: false,
      closeOnClickOverlay: true,
    }).catch((err) => {})
  },

  // 关闭弹窗 》取消轮循
  closePrizeDialog({ detail }) {
    if (this.data.timer) clearInterval(clearInterval(this.data.timer))
    this.data.timer = null
    if (!detail) {
      // 自动关闭，则为核销成功
      Toast.success('兑换成功')
      this.selectAllComponents('#scrollContainer')[0].onPullDownRefresh()
    }
  },
})
